/**
 * @description 数据字典左边编辑弹窗
 * @author 李艳
 */

import React, {Component} from 'react'
import {Checkbox, Form, Input, Modal, Row} from 'antd';
import {checkInputCode, getUserInfo} from "../../../../commons/utils/CommonUtils";

const FormItem = Form.Item;

class EditLeftModal extends Component {
  constructor(props) {
    super(props);
    this.state = {}
  }

  handleClose = () => {
    this.props.form.resetFields();
  };

  componentDidMount() {
    this.props.onRef(this);
  }
  codeLimit=(e)=>{
    let value=e.target.value;
    console.log(value);
    e.target.value=value.replace(/[^a-zA-Z0-9-_.]*/g,"")
  };
  render() {
    const formItemLayout = {
      labelCol: {
        span: 7
      },
      wrapperCol: {
        span: 14
      },
    };

    const {confirmLoading, modalVisible, handleOk, handleCancel, defaultValue, isAdd} = this.props;
    const {getFieldDecorator} = this.props.form;
    let title = "编辑数据字典类型";
    let FormValue = defaultValue;
    if (isAdd) {
      title = "新增数据字典类型";
      FormValue = {}
    }
    return (
      <div>
        <Modal title={title}
               visible={modalVisible}
               onOk={handleOk}
               onCancel={handleCancel}
               width={500}
               afterClose={this.handleClose}
               confirmLoading={confirmLoading}
               maskClosable={false}
               centered={true}
        >
          <Row>
            <FormItem
              style={{display: "none"}}
              label="id">
              {getFieldDecorator('id', {
                initialValue: FormValue.id ? FormValue.id :null,
              })(
                <Input/>
              )}
            </FormItem>
            <FormItem
              label={"代码"}
              {...formItemLayout}
            >
              {getFieldDecorator('code', {
                initialValue: FormValue.code ? FormValue.code : null,
                rules: [{required: true, message: '请填写代码!',whitespace: true},checkInputCode(), {max: 50, message: '代码最大长度为50'}]
              })(
                <Input disabled={!isAdd}/>
              )}
            </FormItem>
            <FormItem
              {...formItemLayout}
              label="名称">
              {getFieldDecorator('name', {
                initialValue: FormValue.name ? FormValue.name : "",
                rules: [{required: true, message: '请填写名称!',whitespace: true}]
              })(
                <Input maxLength={200}/>
              )}
            </FormItem>
            <FormItem
              {...formItemLayout}
              label="描述">
              {getFieldDecorator('remark', {
                initialValue: FormValue.remark ? FormValue.remark : "",
                rules: [{required: true, message: '请填写描述!',whitespace: true}]
              })(
                <Input.TextArea rows={3}/>
              )}
            </FormItem>
            <FormItem
              {...formItemLayout}
              label="冻结">
              {getFieldDecorator('frozen', {
                valuePropName: 'checked',
                initialValue: FormValue.frozen,
              })(
                <Checkbox/>
              )}
            </FormItem>

            </Row>
        </Modal>
      </div>
    );
  }
}

EditLeftModal = Form.create()(EditLeftModal);
export default EditLeftModal;
